<?php
/**
 * Admin for CMS settings
 *
 * <code>
 *  $username = "user";
 *  $realm = "admin";
 *  $password = md5('password');
 *  $passwordForFile = md5("$username:$realm:$password");
 * </code>
 *
 * @author Mario Schillermann <info@rockit-flash.com>
 * @encoding UTF-8 äöüßÖÄÜ
 * @copyright © 2011 Mario Schillermann (info@rockit-flash.com)
 * @license GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @package Page
 * @subpackage Index
 * @link $HeadURL$
 * @version SVN: $Id$
 * @phpVersion >=5
 * @todo
 */

class Admin_LoginController extends Zend_Controller_Action
{
    /**
     * Initialize the general options
     *
     * @return void
     */
    public function init()
    {
        $this->_helper->layout->disableLayout();
    }
    /**
     * Index
     *
     * @return void
     */
    public function indexAction()
    {

        $form = new Admin_Form_Login;
        $getForm = $form->build();

        if ($this->getRequest()->isPost()) {

            if ($form->isValid($_POST)) {

                $filename = APPLICATION_PATH . '/configs/system/users.dat';
                $realm = 'desktop';
                $username = $this->getRequest()->getPost('username');
                $password = md5($this->getRequest()->getPost('password'));
                $adapter = new Zend_Auth_Adapter_Digest(
                    $filename,
                    $realm,
                    $username,
                    $password);

                $result = $adapter->authenticate();
                if($result->isValid()) {
                    $this->_forward('index', $realm);
                }


            } else {
                $this->view->form = $getForm;
            }
        } else {
            $this->view->form = $getForm;
        }

    }
}

